// import s_put from '@feidao/web/atom/browser/storage/put';

import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
// import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import s_put from '@dfeidao/atom-web/storage/put';

import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
// 初始化渲染
export default async function a001(fd: IFeidaoAiBrowserComponent) {
	// const user = await whoami();
	const prid = fd.data.node.querySelector<HTMLSpanElement>('[data-feidao-id="user"]').getAttribute('prid');
	// const user = await whoami(get_user_info);
	// console.log(prid);
	await s_put('productid', prid);
	// set(fd, 'productid', prid);
	// const prid = user.productid;
	const query = {
		filter: {
			productid: prid
		}
	};
	// console.log(query);
	// const res = await nodejs<{ dataArray: object[] }>(url, './permissions/role_type_find', query, false, false);

	const res = await nodejs<{ dataArray: object[] }>('role-type/zj-000001/s001', query);
	if (res.dataArray.length === 0) {
		render(fd, res.dataArray, p002, 'p002', 'inner');
	} else {
		const tb = res.dataArray;
		const data = tb.map((v) => {
			return { ...v, v: JSON.stringify(v) };
		});
		render(fd, data, p001, 'p001', 'inner');
	}
}
